package Year21_Month10.day1017;

public class MyArray<E> {
    private  E[] array;
    private int size;

    //建造构造器
    public MyArray(int size){
        array = (E[]) new Object[size];
        size = 0;
    }

    //构造添加方法
    public void add(E e){
        if(size == array.length){
            throw new ArrayIndexOutOfBoundsException("没地方添加啦！");
        }
        array[size++] = e;
    }

    //得到该数组下标
    public E get(int index){
        if(index > size){
            throw new ArrayIndexOutOfBoundsException("数组下标越界啦！");
        }
        return array[index];
    }

    public int size(){
        return size;
    }

    public static void main(String[] args) {
        Integer a = new Integer(1);
        Integer b = new Integer(1);
        System.out.println(a == b);
    }

    public static void main1(String[] args) {
        Integer a = Integer.valueOf(1);
        Integer b = 1;
        Integer c = (Integer) 1;
        System.out.println(a == b && b== c );

        int i = a.intValue();
        int j = a;
        int k = (int)a;
        System.out.println(i == j && j == k);
    }
}

class Person {
    String name;
    String gender;
    int age;

    public Person(String name, String gender, int age) {
        this.name = name;
        this.gender = gender;
        this.age = age;
    }
}

class Animal {
    String name;
    String color;

    public Animal(String name, String color) {
        this.name = name;
        this.color = color;
    }
}
//下面的代码进行隐藏，是之前的实验。
/*private Object[] array;
    private int size;

    public MyArray(int initCap){
        array = new Object[initCap];
        size = 0;
    }

    public void add(Object p){
        if(size == array.length){
            System.out.println("元素已经存满了，无法再添加元素");
        }
        array[size++] = p;
    }

    public Object get(int index){
        if(index >= size){
            throw new IndexOutOfBoundsException("数组下标越界");
        }
        return array[index];
    }
    public int size(){
        return size;
    }
    public static void main(String[] args) {
        MyArray myArray1 = new MyArray(10);
        myArray1.add(new Person("HanMeiMei", "女", 12));
        myArray1.add(new Person("LiLeiLei", "男", 13));
        myArray1.add(new Person("LiMing", "男", 13));
        myArray1.add(new Person("Wangtiezhu", "男", 13));
        myArray1.add(new Animal("小七", "金黄色"));
        myArray1.add(new Animal("元宝", "灰黑色"));
        System.out.println(myArray1.size());

        Person p1 = (Person) myArray1.get(1);
        System.out.println(p1.name);
        Animal a1 = (Animal)myArray1.get(4);
        System.out.println(a1.name);
    }*/